admin: Use locking for most sysroot commands
authorColin Walters <walters@verbum.org>
Wed, 13 May 2015 20:48:09 +0000 (16:48 -0400)
committerColin Walters <walters@verbum.org>
Wed, 13 May 2015 21:23:07 +0000 (17:23 -0400)
The previous commit introduced locking for `ostree admin deploy`, but
we do expect people to possibly accidentally do e.g.
`ostree admin upgrade` concurrently.

Using consistent locking in the admin commands will help rpm-ostree.

Closes: https://github.com/GNOME/ostree/pull/110
src/ostree/ot-admin-builtin-deploy.c
src/ostree/ot-admin-builtin-diff.c
src/ostree/ot-admin-builtin-init-fs.c
src/ostree/ot-admin-builtin-instutil.c
src/ostree/ot-admin-builtin-os-init.c
src/ostree/ot-main.c
src/ostree/ot-main.h

index 78d60bb5c7545e45f8a6bc7b8622ff5a3e6f5cbc..b054ece4a9b4ec78a15608f10603798606988713 100644 (file)
@@ -79,9 +79,6 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro
 
   refspec = argv[1];
 
-  if (!ot_admin_sysroot_lock (sysroot, error))
-    goto out;
-
   if (!ostree_sysroot_load (sysroot, cancellable, error))
     goto out;
 
@@ -175,8 +172,6 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro
 
   ret = TRUE;
  out:
-  if (sysroot)
-    ostree_sysroot_unlock (sysroot);
   if (origin)
     g_key_file_unref (origin);
   if (context)
index 00032756f483ef0ac86c1792b6e4b7953d1a93bd..85a820ac9368e639bdc4ae75887dfb4dffde6a48 100644 (file)
@@ -55,7 +55,7 @@ ot_admin_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError
   g_option_context_add_main_entries (context, options, NULL);
 
   if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
-                                          OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
+                                          OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
                                           &sysroot, cancellable, error))
     goto out;
   
index eeb5f9f7fe700adedc070afcde239c5bbe9548e0..71b3b55dfbaf9c9121af98e573927d621c4d7cde 100644 (file)
@@ -48,7 +48,7 @@ ot_admin_builtin_init_fs (int argc, char **argv, GCancellable *cancellable, GErr
   context = g_option_context_new ("PATH - Initialize a root filesystem");
 
   if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
-                                          OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
+                                          OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
                                           &sysroot, cancellable, error))
     goto out;
 
index 7479c3a998088377e290dc9381b977f2c2605311..1087b381021d9785dca2ca990fdbe558fe611512 100644 (file)
@@ -116,7 +116,7 @@ ot_admin_builtin_instutil (int argc, char **argv, GCancellable *cancellable, GEr
 
       /* This will not return for some options (e.g. --version). */
       if (ostree_admin_option_context_parse (context, NULL, &argc, &argv,
-                                             OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
+                                             OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
                                              NULL, cancellable, error))
         {
           if (subcommand_name == NULL)
index 52e3d9a560b66c3cbeb7989830ef61e1c9aad389..f5b5f64b1011233934eb0d532842f7bd0605d32e 100644 (file)
@@ -46,7 +46,7 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr
   context = g_option_context_new ("OSNAME - Initialize empty state for given operating system");
 
   if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
-                                          OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
+                                          OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
                                           &sysroot, cancellable, error))
     goto out;
 
index 8aa20838e700f91da42be92bb3dd8c878c07d9aa..7f45b2b46994bd4159567a3b02ef198c71f34d17 100644 (file)
@@ -28,6 +28,7 @@
 #include <string.h>
 
 #include "ostree.h"
+#include "ot-admin-functions.h"
 #include "ot-main.h"
 #include "otutil.h"
 
@@ -362,6 +363,13 @@ ostree_admin_option_context_parse (GOptionContext *context,
       exit (EXIT_SUCCESS);
     }
 
+  if ((flags & OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED) == 0)
+    {
+      /* Released when sysroot is finalized, or on process exit */
+      if (!ot_admin_sysroot_lock (sysroot, error))
+        goto out;
+    }
+
   gs_transfer_out_value (out_sysroot, &sysroot);
 
   success = TRUE;
index 4dd6f4191322da810cc8419594e93536fb6a841f..d893b736a52bb83f218f572e56dfb463d6881636 100644 (file)
@@ -33,7 +33,8 @@ typedef enum {
 
 typedef enum {
   OSTREE_ADMIN_BUILTIN_FLAG_NONE = 0,
-  OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER = 1 << 0
+  OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER = 1 << 0,
+  OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED = 1 << 1
 } OstreeAdminBuiltinFlags;
 
 typedef struct {